/*
 * @Author: your name
 * @Date: 2020-10-20 15:55:04
 * @LastEditTime: 2020-12-08 15:33:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \sende_nuxt\utils\validate.js
 */
/**
 * @param {string} email
 * @returns {Boolean}
 */
const validEmail = (email) => {
    const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return reg.test(email)
}

const Regexs = {  
    email: (/^[0-9a-z][0-9a-z\-\_\.]+@([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}$/i),//邮箱  
    phone: (/^0[0-9]{2,3}[2-9][0-9]{6,7}$/),//座机手机号码  
    ydphpne: (/^((13[4-9])|(15[012789])|147|182|187|188)[0-9]{8}$/),//移动手机号码  
    allphpne: (/^((13[0-9])|(15[0-9])|(18[0-9]))[0-9]{8}$/),//所有手机号码  
    ltphpne: (/^((13[0-2])|(15[56])|(186)|(145))[0-9]{8}$/),//联通手机号码  
    dxphpne: (/^((133)|(153)|(180)|(189))[0-9]{8}$/),//电信手机号码  
    url: (/^http:\/\/([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}(:\d+)?\/[0-9a-z%\-_\/\.]+/i),//网址  
    num: (/[^0-9]/),//数字  
    cnum: (/[^0-9a-zA-Z_.-]/),  
    photo: (/\.jpg$|\.jpeg$|\.gif$|\.png$/i),//图片格式
    typeFile: (/image\/jpg$|image\/jpeg$|image\/gif$|image\/png$/i),//文件类型
    row: (/\n/ig)  
};
const chkFormat = (str, ftype) => {
    var nReg = Regexs[ftype];  
    if (str == null || str == "") return false; //输入为空，认为是验证通过  
    if (ftype == 'num') {  
        if (!nReg.test(str) && !chkChinese(str)) {//10.23 tenfy 必须为数字且不能有中文  
            return true;
        } else {
            return false;  
        }
    }  
    if (nReg.test(str)) {
        return true;  
    } else {  
        return false;
    }  
}
const getUrlParam = (url, paraName) => {
    let arrObj = url.split("?");
    if (arrObj.length > 1) {
        let arrPara = arrObj[1].split("&");
        let arr;
        for (let i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");
            if (arr != null && arr[0] == paraName) return arr[1];
        }
        return "";
    } else {
        return "";
    }
}

export {
    validEmail
    ,chkFormat
    ,getUrlParam
}